
package com.walkingfiles.extjs

class ExtJSConverter {
    
    def includeDocuments

    def ExtJSConverter(includeDocuments=true) {
        this.includeDocuments = includeDocuments
    }

    def contentToTree(alfrescoNode, includeDocuments=true) {
        
        def node = [:] 
        alfrescoNode.each { key, value ->
            node[key] = value
        }
        node['text'] = alfrescoNode['name']
        node['leaf'] = !alfrescoNode['isContainer']

        if (alfrescoNode['isContainer']) {
            def children = alfrescoNode['children'].findAll {
                includeDocuments || it['isContainer']
            }
            node['children'] = children.collect { child ->
                contentToTree(child, includeDocuments)
            }
        }

        node
    }

}

